
var prefix = "/system/config"
$(function() {
	load();
	if($("#type").val()=='医疗器械'){
		$("#medicalInstrument").show();
	}
});

function load() {
	$.ajax({
		cache : true,
		type : "GET",
		url : "/common/dict/list/医疗器械随行单编号",
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			for(let i = 0; i < data.length; i++){
				$("#withOrderNo").append("<option value='"+data[i].value+"'>"+data[i].name+"</option>");
			}
		}
	});
	$.ajax({
		cache : true,
		type : "GET",
		url : "/common/dict/list/储运条件",
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			for(let i = 0; i < data.length; i++){
				$("#transCondition").append("<option value='"+data[i].value+"'>"+data[i].name+"</option>");
			}
		}
	});
	$.ajax({
		cache : true,
		type : "GET",
		url : "/common/dict/list/经办人",
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			for(let i = 0; i < data.length; i++){
				$("#operator").append("<option value='"+data[i].value+"'>"+data[i].name+"</option>");
			}
		}
	});

	$.ajax({
		cache : true,
		type : "GET",
		url : "/common/dict/list/供货单位",
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			for(let i = 0; i < data.length; i++){
				$("#supplier").append("<option value='"+data[i].value+"'>"+data[i].name+"</option>");
			}
		}
	});
}

function batchPrint() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/system/config/batchPrint",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success :function(data) {
			console.log(data)
			if(data.code !=0){
				parent.layer.alert(data.msg);
				return;
			}
			for(let i=0;i<data.printList.length;i++){
				console.log(data.printList[i]);
				$.ajax({
					type:"POST",
					url:"https://www.buchang.com/reportService/createHtml",
					contentType: "application/json",
					dataType:"json",
					async:false,
					data:JSON.stringify(data.printList[i]),
					success:function (data) {
						if(null !=data){
							console.log(data);
							let lodop = getLodop();
							if(!lodop){
								alert('请联系管理员，先安装LODOP打印控件!');
								return;
							}
							// lodop.SET_LICENSES("北京中电兴发科技有限公司","BC32B3E98EE17DECE56AD090A683CA08","北京中電興發科技有限公司","581DC03916E72807C08528A17E4F906F");
							LODOP.SET_LICENSES("陕西步长制药有限公司","301FB96D00854CD8E772F67A393C53F6AE2","陜西步長制藥有限公司","006E1D5029146C3080667668828B999FC5B");
							lodop.SET_PRINT_STYLE("FontSize",6);
							// lodop.SET_PRINT_PAGESIZE(1, "300mm", "200mm", "A4");
							lodop.SET_PRINT_PAGESIZE(1, 2410, 1400, "");
							data.forEach(function(script) {
								lodop.ADD_PRINT_HTM("2mm","10mm","RightMargin:10mm","BottomMargin:5mm", script);
								lodop.NEWPAGE();
							});
							// lodop.PREVIEW(); // 打印预览
							LODOP.PRINT(); //直接打印
						}

					}
				})
			}
		}
	});
}

